package com.isdepci.framework.task;


import com.isdepci.common.utils.StringUtils;
import com.isdepci.common.utils.sql.MysqlUtil;
import com.isdepci.project.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定时任务 数据库备份
 */
@Component("mySqlTask")
public class MySqlTask {

    @Autowired
    private ISysConfigService configService;

    /** 数据库安装地址 */
    public static final String MYSQL_PATH = "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\";
    /** 数据库备份地址 */
    public static final String MYSQL_BACKUP = "E:\\java\\csepd_sourse_storage\\mysqlBackup\\";

    /** 链接数据库 */
    public static final String ADDRESS = "127.0.0.1";
    public static final String DATABASE_NAME = "csepd_sourse_storage";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "123456a?";


    public void backup() {
        String mysqlPath = configService.selectConfigByKey("mysqlPath");
        if(StringUtils.isEmpty(mysqlPath)){
            mysqlPath = MYSQL_PATH;
        }
        String mysqlBackup = configService.selectConfigByKey("mysqlBackup");
        if(StringUtils.isEmpty(mysqlBackup)){
            mysqlBackup = MYSQL_BACKUP;
        }
        MysqlUtil.backup(mysqlPath,mysqlBackup,ADDRESS,DATABASE_NAME,USERNAME,PASSWORD);
    }

}
